<cfparam name="CSAC_Order_ID" type="integer" default="0"/>
<cfparam name="returnView" type="string" default="orders"/>
<cfparam name="passback" type="string" default=""/>
<cfif CSAC_Order_ID gt 0>
	<!--- Get order --->
	<cfscript>
		base = new assets.calgrants.com.Base();
		passbackQueryString = base.passbackToQueryString(passback);
		csacOrderGateway = new assets.calgrants.com.gateway.CSACOrderGateway();
		csacOrder = csacOrderGateway.get(CSAC_Order_ID = CSAC_Order_ID);
	</cfscript>
	<cfif csacOrder.getCSAC_Order_ID() gt 0>
		<cfscript>
			workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
			qWorkshops = workshopGateway.query(workshopIDs = csacOrder.getWorkshop_IDs());
		</cfscript>
		<cfquery name="getWorkshopTotals" dbtype="query">
			select Sum(Anticipated_Students) as totalAnticipatedStudents, 
			Sum(Anticipated_Volunteers) as totalAnticipatedVolunteers, 
			Sum(Anticipated_Computers) as totalAnticipatedComputers, 
			Min(Anticipated_Volunteers) as minimumUniqueVolunteers 
			from qWorkshops
		</cfquery>
		<cfscript>
			// set Total... and Unique_Volunteers
			totalAnticipatedStudents = getWorkshopTotals.totalAnticipatedStudents;
			totalAnticipatedVolunteers = getWorkshopTotals.totalAnticipatedVolunteers;
			totalAnticipatedComputers = getWorkshopTotals.totalAnticipatedComputers;
			//minimumUniqueVolunteers = getWorkshopTotals.minimumUniqueVolunteers;
			// Load up WMS objects
			organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
			organization = organizationGateway.get(Organization_ID = csacOrder.getOrganization_ID());
			userGateway = new assets.calgrants.com.gateway.UserGateway();
			orderedBy = userGateway.get(User_ID = csacOrder.getOrdered_By_ID());
			// Load up CSAC objects
			csacBase = new assets.csac.com.Base();
			statuses = csacBase.getOrderStatuses();
			institutionTypes = csacBase.getInstitutionTypes();
			csacGateway = new assets.csac.com.gateway.Gateway();
			institutions = csacGateway.call(objType = "view", obj = "getInstitutions");
			highSchools = csacGateway.call(objType = "view", obj = "getHighSchools");
			cities = csacGateway.call(objType = "view", obj = "getCities");
			orderProductGateway = new assets.csac.com.gateway.OrderProductGateway();
			productGateway = new assets.csac.com.gateway.ProductGateway();
			qOrderProducts = orderProductGateway.query(Order_ID = csacOrder.getOrder_ID(), Deleted = 0);
			orderProductProductIDs = ValueList(qOrderProducts.Product_ID);
			qProducts = productGateway.query(productIDs = orderProductProductIDs);
			trackingGateway = new assets.csac.com.gateway.TrackingGateway();
			qTrackings = trackingGateway.query(Deleted = 0, Order_ID = csacOrder.getOrder_ID());
		</cfscript>
		<!--- Get institution name if high school or college/university --->
		<cfif csacOrder.getCSAC_Order_ID() gt 0>
			<cfif csacOrder.getInstitution_Type() eq "Other">
				<cfset institution = csacOrder.getInstitution()/>
				<cfelseif csacOrder.getInstitution_Type() eq "High School">
				<cfquery name="qHighSchool" dbtype="query">
						select High_School
						from highSchools
						where High_School_ID = #csacOrder.getInstitution_ID()#
					</cfquery>
				<cfset institution = qHighSchool.High_School/>
				<cfelseif csacOrder.getInstitution_Type() eq "College University">
				<cfquery name="getCollegeUniversity" dbtype="query">
						select Institution
						from institutions
						where Institution_ID = #csacOrder.getInstitution_ID()#
					</cfquery>
				<cfset institution = getCollegeUniversity.Institution/>
				<cfelse>
				<cfset institution = ""/>
			</cfif>
		</cfif>
		<style>
			table tr td small {
				font-size: 0.8em;
			}
		</style>
		<script type="text/javascript">
			$(function () {
				$("#csacOrderModal").modal();
				resizeModal("csacOrderModal");
			})
		</script>
		<div id="csacOrderModal" class="modal modal-fullscreen" data-backdrop="static">
			<div class="modal-header">
				<cfoutput>
					<h3>Order ###csacOrder.getOrder_ID()#</h3>
				</cfoutput>
			</div>
			<!--- modal body --->
			<div class="modal-body">
				<div class="container-fluid" style="background-color: white;">
					<div class="row-fluid">
						<div class="span12">
							<h4>Shipping Information</h4>
						</div>
					</div>
					<div class="row-fluid">
						<cfoutput>
							<div class="span4">
								<h5>Recipient</h5>
								#csacOrder.getFirst_Name()# #csacOrder.getLast_Name()#<br/>
								#csacOrder.getEmail()#<br/>
								#csacOrder.getPhone()#<cfif Len(Trim(csacOrder.getExtension())) gt 0> x #csacOrder.getExtension()#</cfif>
							</div>
							<div class="span4">
								<h5>Shipping Address</h5>
								#institution#<br/>
								<cfif Len(Trim(csacOrder.getDepartment())) gt 0>
									#csacOrder.getDepartment()#<br/>
								</cfif>
								#csacOrder.getAddress1()#<br/>
								<cfif Len(Trim(csacOrder.getAddress2())) gt 0>
									#csacOrder.getAddress2()#<br/>
								</cfif>
								#csacOrder.getCity()#, CA #csacOrder.getZip_Code()# 
							</div>
							<div class="span4">
								<h5>Shipping Instructions</h5>
								<cfif Len(Trim(csacOrder.getShipping_Instructions())) gt 0>
									#csacOrder.getShipping_Instructions()#
								<cfelse>
									None
								</cfif>
								<h5>Notes</h5>
								<cfif Len(Trim(csacOrder.getShared_Notes())) gt 0>
									#csacOrder.getShared_Notes()#
								<cfelse>
									None
								</cfif>
								<h5>Tracking Codes</h5>
								<cfif qTrackings.RecordCount gt 0>
									<cfloop query="qTrackings">
										<a href="https://www.fedex.com/fedextrack/?tracknumbers=#Tracking_Code#" target="_blank">#Tracking_Code#</a><br />
									</cfloop>
								<cfelse>
									None
								</cfif>
							</div>
						</cfoutput>
					</div>
					<div class="row-fluid">
						<div class="span12">
							<h4>Workshops</h4>
							<table class="table table-bordered">
								<thead>
									<tr>
										<td><strong>Workshop</strong></td>
										<td width="100"><strong>Anticipated Students</strong></td>
										<td width="100"><strong>Anticipated Volunteers</strong></td>
										<td width="100"><strong>Anticipated Computers</strong></td>
									</tr>
								</thead>
								<tbody>
									<cfoutput query="qWorkshops" group="Site">
										<cfoutput>
											<tr>
												<td>#Site#<br/>
													#DateFormat(Workshop_Date, "m/d/yyyy")# #TimeFormat(Start_Time, "h:mmtt")# -#TimeFormat(End_Time, "h:mmtt")#</td>
												<td>#Anticipated_Students#</td>
												<td>#Anticipated_Volunteers#</td>
												<td>#Anticipated_Computers#</td>
											</tr>
										</cfoutput>
									</cfoutput>
								</tbody>
							</table>
						</div>
					</div>
					<div class="row-fluid">
						<div class="span12">
							<cfoutput>
								<ul class="thumbnails">
									<li class="col110" style="margin-left: 0; margin-bottom: 10px;">
										<div class="thumbnail" style="padding: 12px;">
											<div id="totalAnticipatedStudents" class="anticipatedCount">#totalAnticipatedStudents#</div>
											<label>Total<br />Anticipated<br />Students</label>
										</div>
									</li>
									<li class="col120" style="margin-bottom: 10px;">
										<div class="thumbnail" style="padding: 12px;">
											<div id="totalAnticipatedVolunteers" class="anticipatedCount">#totalAnticipatedVolunteers#</div>
											<label>Total<br />Anticipated<br />Volunteers</label>
										</div>
									</li>
									<li class="col120" style="margin-bottom: 10px;">
										<div class="thumbnail" style="padding: 12px;">
											<div id="uniqueVolunteers" class="anticipatedCount">#csacOrder.getUnique_Volunteers()#</div>
											<label>Total<br />Unique<br />Volunteers</label>
										</div>
									</li>
									<li class="col120" style="margin-bottom: 10px;">
										<div class="thumbnail" style="padding: 12px;">
											<div id="totalAnticipatedComputers" class="anticipatedCount">#totalAnticipatedComputers#</div>
											<label>Total<br />Anticipated<br />Computers</label>
										</div>
									</li>
								</ul>
							</cfoutput>
						</div>
					</div>
					<div class="row-fluid">
						<div class="span12">
							<h4>Materials</h4>
							<cfoutput query="qProducts" group="Category">
								<cfoutput group="Subcategory">
									<h5>#Category#<cfif Len(Subcategory) gt 0> - #Subcategory#</cfif></h5>
									<table class="table table-bordered">
										<thead>
											<tr>
												<td><strong>Item</strong></td>
												<td width="100"><strong>Quantity</strong></td>
											</tr>
										</thead>
										<tbody>
											<cfoutput>
												<cfquery name="qOrderProduct" dbtype="query">
													select *
													from qOrderProducts
													where Product_ID = #Product_ID#
												</cfquery>
												<cfif qOrderProduct.RecordCount gt 0>
													<cfset opID = qOrderProduct.Order_Product_ID/>
													<cfset qty = qOrderProduct.Quantity/>
													<cfset qtyShipped = qOrderProduct.Quantity_Shipped/>
												<cfelse>
													<cfset opID = 0/>
													<cfset qty = 0/>
													<cfset qtyShipped = 0/>
												</cfif>
												<tr>
													<td>#Product#<br/>
														<small>
														<cfif Len(Trim(Description)) gt 0>
															#Description#
														</cfif>
														<cfif Len(Trim(ID)) gt 0>
															Item ID #ID#.
														</cfif>
														</small></td>
													<td>
														<cfif Download_Only eq 1>
															<small>Download only</small>
															<cfelseif Inventory eq 1 and Stock lte 0 and Allow_Back_Order eq 0>
															<small>Out of stock</small>
															<cfelse>
															#qty#
														</cfif>
													</td>
												</tr>
											</cfoutput>
										</tbody>
									</table>
								</cfoutput>
							</cfoutput>	
						</div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<cfoutput>
					<a href="?view=#returnView#&#passbackQueryString#" class="btn btn-success">Close</a>
				</cfoutput>
			</div>
		</div>
	<cfelse>
		<!--- No workshops available modal ---> 
		<script type="text/javascript">
			$(function () {
				$("#noWorkshopsModal").modal();
				resizeModal("noWorkshopsModal");
			})
		</script> 
		<cfoutput>
			<div id="noWorkshopsModal" class="modal modal-fullscreen" data-backdrop="static">
				<div class="modal-header">
					<h3>No Workshops</h3>
				</div>
				<div class="modal-body">
					<div class="container-fluid">
						<div class="row-fluid">
							<div class="span12">
								<h4>No workshops available for order</h4>
								<cfif IsUserInRole("Super User") or IsUserInRole("Regional Admin")>
									<p>There are no workshops registered for this organization.</p>
								<cfelse>
									<p>To place an order there must be at least one registered workshop that meets both of the following conditions:</p>
									<ol>
										<li>Occurs in the future</li>
										<li>Has not already been submitted with an order</li>
									</ol>
								</cfif>
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<a href="?view=#returnView#&#passbackQueryString#" class="btn btn-success">Close</a>
				</div>
			</div>
		</cfoutput>
	</cfif>
<cfelse>
	<div class="alert alert-info notFound">Order not found</div>
</cfif>

<!--- 
<h2>Shipping Information</h2>
<table>
	<cfoutput>
		<tr valign="top">
			<td>
				<h3>Shipping Recipient & Address</h3>
				<p> 
					#csacOrder.getFirst_Name()# #csacOrder.getLast_Name()#<br/>
					#institution#<br/>
					<cfif Len(Trim(csacOrder.getDepartment())) gt 0>
						#csacOrder.getDepartment()#<br/>
					</cfif>
					#csacOrder.getAddress1()#<br/>
					<cfif Len(Trim(csacOrder.getAddress2())) gt 0>
						#csacOrder.getAddress2()#<br/>
					</cfif>
					#csacOrder.getCity()#, CA #csacOrder.getZip_Code()# 
				</p>
				<h3>Contact Info</h3>
				<p> 
					#csacOrder.getEmail()#<br/>
					#csacOrder.getPhone()#
					<cfif Len(Trim(csacOrder.getExtension())) gt 0>
						x#csacOrder.getExtension()#
					</cfif>
				</p>
			</td>
			<td>
				<h3>Shipping&nbsp;Instructions</h3>
				<p>
					<cfif Len(Trim(csacOrder.getShipping_Instructions())) gt 0>
						#csacOrder.getShipping_Instructions()#
						<cfelse>
						None
					</cfif>
				</p>
				<h3>Notes</h3>
				<p>
					<cfif Len(Trim(csacOrder.getShared_Notes())) gt 0>
						#csacOrder.getShared_Notes()#
						<cfelse>
						None
					</cfif>
				</p>
			</td>
		</tr>
	</cfoutput>
	<tr>
		<td colspan="2">
			<h2>Workshops</h2>
			<table class="table table-bordered">
				<thead>
					<tr>
						<td><strong>Workshop</strong></td>
						<td width="100"><strong>Anticipated Students</strong></td>
						<td width="100"><strong>Anticipated Volunteers</strong></td>
						<td width="100"><strong>Anticipated Computers</strong></td>
					</tr>
				</thead>
				<tbody>
					<cfoutput query="qWorkshops" group="Site">
						<cfoutput>
							<tr>
								<td>#Site#<br/>
									#DateFormat(Workshop_Date, "m/d/yyyy")# #TimeFormat(Start_Time, "h:mmtt")# -#TimeFormat(End_Time, "h:mmtt")#</td>
								<td>#Anticipated_Students#</td>
								<td>#Anticipated_Volunteers#</td>
								<td>#Anticipated_Computers#</td>
							</tr>
						</cfoutput>
					</cfoutput>
				</tbody>
			</table>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<h2>Materials</h2>
			<cfoutput query="qProducts" group="Category"> <cfoutput group="Subcategory">
					<h3>#Category#
						<cfif Len(Subcategory) gt 0>
							- #Subcategory#
						</cfif>
					</h3>
					<table class="table table-bordered">
						<thead>
							<tr>
								<td><strong>Item</strong></td>
								<td width="100"><strong>Quantity</strong></td>
							</tr>
						</thead>
						<tbody>
							<cfoutput>
								<cfquery name="qOrderProduct" dbtype="query">
									select *
									from qOrderProducts
									where Product_ID = #Product_ID#
								</cfquery>
								<cfif qOrderProduct.RecordCount gt 0>
									<cfset opID = qOrderProduct.Order_Product_ID/>
									<cfset qty = qOrderProduct.Quantity/>
									<cfset qtyShipped = qOrderProduct.Quantity_Shipped/>
								<cfelse>
									<cfset opID = 0/>
									<cfset qty = 0/>
									<cfset qtyShipped = 0/>
								</cfif>
								<tr>
									<td>#Product#<br/>
										<small>
										<cfif Len(Trim(Description)) gt 0>
											#Description#
										</cfif>
										<cfif Len(Trim(ID)) gt 0>
											Item ID #ID#.
										</cfif>
										</small></td>
									<td>
										<cfif Download_Only eq 1>
											<small>Download only</small>
											<cfelseif Inventory eq 1 and Stock lte 0 and Allow_Back_Order eq 0>
											<small>Out of stock</small>
											<cfelse>
											#qty#
										</cfif>
									</td>
								</tr>
							</cfoutput>
						</tbody>
					</table>
				</cfoutput>
			</cfoutput>
		</td>
	</tr>
</table>
 --->
